package cn.yuan;

import cn.yuan.quartz.jobs.PrintTimeJob;
import cn.yuan.quartz.utils.QuartzUtils;
import org.junit.Test;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

public class QuartzUtilsTest {
    @Autowired
    private SchedulerFactoryBean schedulerFactory;

    @Test
    public void testUtils() throws SchedulerException, InterruptedException {
        Scheduler scheduler = schedulerFactory.getScheduler();
        String jobName = "myPrinttimeJob";
        String params = "你好，job";
        String cronStr = "0/1 * * * * ? *";
        QuartzUtils.addJob(scheduler, jobName, PrintTimeJob.class, params, cronStr);
        Thread.sleep(10000);
        QuartzUtils.removeJob(scheduler, jobName);
        Thread.sleep(10000);
    }
}
